package com.ly.drivingschool.service.impl;

import com.ly.drivingschool.dao.StaffDao;
import com.ly.drivingschool.pojo.Pager;
import com.ly.drivingschool.pojo.Staff;
import com.ly.drivingschool.pojo.User;
import com.ly.drivingschool.service.StaffService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 员工操作
 */
@Slf4j
@Service
public class StaffServiceImpl implements StaffService {

    @Autowired
    private StaffDao staffDao;

    /**
     * 根据id删除一条记录
     * @param staffId
     * @return
     */
    @Override
    public int deleteByPrimaryKey(Integer staffId) {
        int code = staffDao.deleteByPrimaryKey(staffId);
        return code;
    }

    /**
     * 批量删除多条记录
     * @param array
     * @return
     */
    @Override
    public int deleteByBatchStaff(int[] array) {
        int code = staffDao.deleteByBatchStaff(array);
        return code;
    }

    /**
     * 添加一条新纪录
     * @param record
     * @return
     */
    @Override
    public int insertSelective(Staff record) {
        int code = staffDao.insertSelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 查询一条记录
     * @param staff_id
     * @return
     */
    @Override
    public Staff selectByPrimaryKey(Integer staff_id) {
        Staff staff = staffDao.selectByPrimaryKey(staff_id);
        return staff;
    }

    /**
     * 更新一条记录
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKeySelective(Staff record) {
        int code = staffDao.updateByPrimaryKeySelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 分页查询
     * @param page
     * @return
     */
    @Override
    public Pager<Staff> findByPager(int page, int size) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        Pager<Staff> pager = new Pager<Staff>();
        List<Staff> list = staffDao.findByPager(params);
        pager.setData(list);
        pager.setCount(staffDao.count());
        return pager;
    }

    /**
     * 模糊查询
     * @param page
     * @param size
     * @param keyWork
     * @return
     */
    @Override
    public Pager<Staff> findByKey(int page, int size, String keyWork) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        params.put("keyWork", keyWork);
        Pager<Staff> pager = new Pager<Staff>();
        List<Staff> list = staffDao.findByKey(params);
        pager.setData(list);
        pager.setCount(staffDao.countKey(keyWork));
        return pager;
    }

    /**
     * 条件查询
     * @param page
     * @param size
     * @param col
     * @param code
     * @return
     */
    @Override
    public Pager<Staff> findByCondition(int page, int size,String col,String code) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("page", (page-1)*size);
        params.put("size", size);
        params.put("col", col);
        params.put("code", code);
        Pager<Staff> pager = new Pager<Staff>();
        List<Staff> list = staffDao.findByCondition(params);
        pager.setData(list);
        pager.setCount(staffDao.countZG001(col,code));
        return pager;
    }

    @Override
    public long count() {
        return 0;
    }

    @Override
    public long countZG001(String col, String code) {
        return 0;
    }

    @Override
    public long countKey(String keyWork) {
        return 0;
    }

    /**
     * 根据员工类型查询相应的员工
     * @param zg001
     * @return
     */
    @Override
    public List<Staff> getStaffByZG001(String zg001) {
        List<Staff> staff = staffDao.getStaffByZG001(zg001);
        return staff;
    }

    /**
     * 查询不带字典值的信息 code
     * @param staff_id
     * @return
     */
    @Override
    public Staff findByDict(Integer staff_id) {
        Staff staff = staffDao.findByDict(staff_id);
        return staff;
    }

    /**
     * 更新一条记录
     * @param record
     * @return
     */
    @Override
    public int updateByPrimaryKey(Staff record) {
        int code = staffDao.updateByPrimaryKeySelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }

    /**
     * 添加新员工
     * @param record
     * @return
     */
    @Override
    public int insert(Staff record) {
        int code = staffDao.insertSelective(record);
        if (code == 0) {
            return 0;
        } else {
            return 1;
        }
    }
}
